package com.sl.plugin.step.json;


import cn.hutool.core.util.StrUtil;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import com.sl.core.engine.meta.impl.AbstractProcessCompDescriptor;
import com.sl.core.engine.step.ProcessCompService;
import com.sl.core.engine.step.impl.AbstractProcessComp;
import com.sl.core.engine.utils.BeanUtil;

import java.util.Map;

/**
 *
 */
public class JsonFilterComp extends AbstractProcessComp<Map<String, Object>, Map<String, Object>> implements ProcessCompService {


    public JsonFilterComp(AbstractProcessCompDescriptor abstractProcessCompDescriptor) {
        super(abstractProcessCompDescriptor);
    }

    @Override
    public Map<String, Object> input(Map<String, Object> param) {
        Map<String, Object> am = meta.getAttributeMap();
        DocumentContext parse = JsonPath.parse(param);
        String jsonPath = BeanUtil.getStr(am, "config.excludeJsonPath");
        if (StrUtil.isNotBlank(jsonPath)) {
            parse.delete(jsonPath);

        }
        return parse.json();

    }

}
